﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace fap
{
    /// <summary>
    /// Page1.xaml 的交互逻辑
    /// </summary>
    public partial class 主页 : Page
    {
        public 主页()
        {
            InitializeComponent();
        }



        public DispatcherTimer timer;

        void timer_Tick(object sender, EventArgs e)
        {

            Timer1.Text = DateTime.Now.ToString("yyyy-dd-MM HH:mm:ss");
        }





        private void Page_Initialized(object sender, EventArgs e)
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

            Storyboard 旋转 = Resources["图像旋转"] as Storyboard;
            旋转.Begin();
            Thread s = new Thread(显示页面);
            s.Start();
        }


        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Image obj = (Image)sender;
            switch (obj.Tag)
            {

                case "返回":
                    {
                        //NavigationService.Navigate(窗口.主界面);
                        break;
                    }
                case "退出":
                    {

                        提示页面 form = new 提示页面("确定要退出程序吗？");
                        form.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        form.ShowDialog();
                        //   Application.Exit();  //强制所有消息中止，退出所有的窗体，但是若有托管线程（非主线程），也无法干净地退出；  

                        // Application.ExitThread(); //强制中止调用线程上的所有消息，同样面临其它线程无法正确退出的问题；  
                        if (form.是否)
                        {
                            form.Close();
                            System.Environment.Exit(0);   //这是最彻底的退出方式，不管什么线程都被强制退出，把程序结束的很干净，退出时有可能会抛出异常  
                        }
                        else
                        {
                            form.Close();
                        }


                        //  System.Diagnostics.Process tt = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id);
                        // tt.Kill();//直接杀死与本程序相关的所有进程，有可能会导致数据丢失，但是不会抛出异常。

                        break;
                    }
            }

        }


        private void 鼠标进入(object sender, MouseEventArgs e)
        {
            Image ig = sender as Image;
            switch (ig.Tag.ToString())
            {

                case "退出":
                    {
                        Uri ur = new Uri("/fap;component/素材/公用/退出.png", UriKind.Relative);
                        BitmapImage bp = new BitmapImage(ur);
                        ig.Source = bp;


                        break;
                    }

            }
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, 300);
            WPF相应类.ScaleEasingAnimationShow(ig, 1, 1.1, 2, timeSpan);
        }
        private void 鼠标离开(object sender, MouseEventArgs e)
        {
            Image ig = sender as Image;
            switch (ig.Tag.ToString())
            {

                case "退出":
                    {
                        Uri ur = new Uri("/fap;component/素材/公用/退出.png", UriKind.Relative);
                        BitmapImage bp = new BitmapImage(ur);
                        ig.Source = bp;


                        break;
                    }


            }
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, 300);
            WPF相应类.ScaleEasingAnimationShow(ig, 1.1, 1, 2, timeSpan);
        }


        private void Page_Loaded_1(object sender, RoutedEventArgs e)
        {



        }


        public void 显示页面()
        {
            Dispatcher.Invoke((Action)(() =>
            {
                Thread.Sleep(1000);
                切换框.Content = 窗口.主页主显示;
            }));

        }
        public void 切换界面(int x)
        {
            switch (x)
            {
                case 0:
                    {
                        NavigationService.Navigate(窗口.主页);

                        break;
                    }

                case 1:
                    {

                        NavigationService.Navigate(窗口.主页辅显示);

                        break;
                    }

                case 3:
                    {
                        NavigationService.Navigate(窗口.运动控制);

                        break;
                    }
                case 4:
                    {
                        NavigationService.Navigate(窗口.统计);

                        break;
                    }
                case 5:
                    {

                        break;
                    }

            }

        }



        public System.Windows.Media.Imaging.BitmapImage 导入图片(bool bol)
        {
            System.Windows.Media.Imaging.BitmapImage s = null;

            if (bol)
            {
                Dispatcher.Invoke((Action)(() =>
                {
                    s = new System.Windows.Media.Imaging.BitmapImage(new Uri("/fap;component/素材/运动控制页面/绿灯.png", UriKind.Relative));

                }));
            }
            else
            {
                Dispatcher.Invoke((Action)(() =>
                {
                    s = new System.Windows.Media.Imaging.BitmapImage(new Uri("/fap;component/素材/运动控制页面/红灯.png", UriKind.Relative));

                }));
            }

            return s;

        }


    }
}
